<?php

namespace app\admin\model;

use think\Model;

class CompanyBalanceLog extends Model {

    //定义类型常量
    public static $out = 2;
    public static $in = 1;
    //自定义明细
    public static $title = [
        'cancel_order' => '取消订单',
        'create_order' => '发布订单',
        'pay' => '在线充值',
    ];
    // 追加属性
    protected $append = [
        'type_text'
    ];

    public function getTypeTextAttr($value, $data) {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = ['2'=>'支出','1'=>'收入'];
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function admin() {
        return $this->belongsTo('Admin', 'admin_id')->setEagerlyType(0);
    }

}
